package com.example.postfix_calculation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText editText_infix = (EditText)findViewById(R.id.editText_infix);
        final EditText editText_suffix = (EditText)findViewById(R.id.editText_suffix);
        final EditText editText_output = (EditText)findViewById(R.id.editText_output);
        final EditText editText_stack = (EditText)findViewById(R.id.editText_stack);
        final EditText editText_stack_calculator = (EditText)findViewById(R.id.editText_stack_calculate);
        Button button1 = (Button)findViewById(R.id.button1);
        Button button2 = (Button)findViewById(R.id.button2);
        Button button3 = (Button)findViewById(R.id.button3);
        Button button4 = (Button)findViewById(R.id.button4);
        Button button5 = (Button)findViewById(R.id.button5);
        final String[] infix = new String[1];
        final String[] suffix = new String[1];
        final String[] output = new String[1];


        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Formula formula = new Formula();
                //  随机生成中缀表达式
                infix[0] = formula.MakeFormula(3);
                editText_infix.setText(infix[0]);
            }
        });

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                suffix[0] = StringToArithmetic.infixToSuffix(infix[0]);
                editText_suffix.setText(suffix[0]);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                output[0] = String.valueOf(StringToArithmetic.suffixToArithmetic(suffix[0]));
                editText_output.setText(output[0]);
            }
        });

        button4.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                editText_stack.setText(infix_suffix.infixToSuffix(infix[0]));
            }
        });

        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText_stack_calculator.setText(suffx_calculation.suffixToArithmetic(suffix[0]));
            }
        });
    }
}
